package com.springboot.service.job;


import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author Administrator
 */
public class TestQuartzJob implements Job {

    private static final Logger logger = LoggerFactory.getLogger(TestQuartzJob.class);

    /**
     * 执行业务逻辑的地方
     * @param jobExecutionContext
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext){
        Object obj = jobExecutionContext.getJobDetail().getJobDataMap().get("obj");
        Method method = (Method) jobExecutionContext.getJobDetail().getJobDataMap().get("method");
        method.setAccessible(true);
        try {
            method.invoke(obj);
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
        Thread current = Thread.currentThread();
        logger.info("QuartzJobDemo.execute 定时任务Quartz:"+current.getId()+ ",name:"+current.getName());
    }
}
